﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static X23.Util.CacheUtil.CacheConst;

namespace X23.Util.CacheUtil
{
    /// <summary>
    /// 缓存接口
    /// </summary>
    public interface ICacheService
    {
        /// <summary>
        /// 获取缓存
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        Task<string> GetAsync(string key);
        /// <summary>
        /// 获取或者创建缓存
        /// </summary>
        /// <param name="key"></param>
        /// <param name="func"></param>
        /// <param name="minutes">缓存时间间隔(分钟) [默认60分钟]</param>
        /// <param name="expirationType">过期类型(1绝对过期 2滑动过期) [默认1绝对过期]</param>
        /// <returns></returns>
        Task<string> GetOrCreateAsync(string key, Func<Task<string>> func, int minutes = 60, ExpirationType expirationType = ExpirationType.AbsoluteExpiration);
        /// <summary>
        /// 设置缓存值
        /// </summary>
        /// <param name="key"></param>
        /// <param name="val"></param>
        /// <param name="minutes">缓存时间间隔(分钟) [默认60分钟]</param>
        /// <param name="expirationType">过期类型(1绝对过期 2滑动过期) [默认1绝对过期]</param>
        /// <returns></returns>
        Task<bool> SetAsync(string key, string val, int minutes = 60, ExpirationType expirationType = ExpirationType.AbsoluteExpiration);
        /// <summary>
        /// 删除缓存
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        Task<bool> RemoveAsync(string key);
        /// <summary>
        /// 缓存值自增
        /// </summary>
        /// <param name="key"></param>
        /// <param name="inc"></param>
        /// <returns></returns>
        Task<int> IncrementAsync(string key, int inc = 0);
    }
}
